<template>
	<view class="container">
		<view class="panel-header padding-top solid-bottom">
			<view class="g-goBack" @click="$utils.toBack()">
				<view class="cuIcon-back"></view>
			</view>
			<view class="text-cut">{{title}}</view>
		</view>
		<form>
			<view class="cu-form-group" v-if="info.id">
				<view class="title">模版ID</view>
				<view class="text-gray padding-right-sm">{{info.id}}</view>
			</view>
		    <view class="cu-form-group">
				<view class="title">模版名称</view>
				<input placeholder="请填写(必填项)" v-model="info.title"></input>
		    </view>
			<view class="cu-form-group">
				<view class="title">押金(元)</view>
				<input placeholder="请填写(必填项)" v-model="info.depositPrice"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">日封顶额(元)</view>
				<input placeholder="请填写(必填项)" v-model="info.dayMaxPrice"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">单价价格(元/小时)</view>
				<input placeholder="请填写(必填项)" v-model="info.payIntervalPrice"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">免费时间</view>
				<input placeholder="请填写(必填项)" v-model="info.freeTimes"></input>
			</view>
			<view class="cu-bar btn-group margin-top">
			    <button class="cu-btn bg-grey shadow-blur round" @click="$utils.toBack()">取消</button>
				<button class="cu-btn bg-orange shadow-blur round" @click="btnSaveSubmit()">确定</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:'新增户外电池价格模版',
				info:{},
			};
		},
		onLoad(option) {
			const _self = this;
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('fromData', function(data) {
			    console.log(data)
				_self.info = Object.assign({},data);
				if(data.id){
					_self.title = "修改户外电池价格模版";
				}
			})
		},
		methods:{
			btnSaveSubmit:function(){
				let info = this.info;
				console.log(info);
				const _self = this;
				const api = this.$request;
				api.post(api.url.bxscnFeeSave,info,res=>{
					console.log(res);
					if(res.code==200){
						uni.showToast({
							title:'保存成功',
							icon:'success'
						})
						setTimeout(function(){
							uni.navigateBack();
						},1000)
					}else if(res.msg){
						uni.showModal({
							title:'保存失败',
							content:res.msg,
							showCancel:false
						})
					}else {
						uni.showToast({
							title:'保存失败',
							icon:'error'
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
.container .cu-form-group{text-align:right;}
</style>
